package com.qijian.common.config.jackson.serialize;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.apache.commons.collections.CollectionUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class LongListToStringSerialize extends JsonSerializer<List<Long>> {

    @Override
    public void serialize(List<Long> values, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if(!CollectionUtils.isEmpty(values)){
            List<String> resList = new ArrayList<>(values.size());
            for (Long value : values) {
                resList.add(String.valueOf(value));
            }
            jsonGenerator.writeObject(resList);
        }
    }
}
